/*********************************************************************************
 *      Copyright:  (C) 2015 songyong<handy_skyoutlook.com>
 *                  All rights reserved.
 *
 *       Filename:  GpsMain.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(2015年08月11日)
 *         Author:  sky <handy_sky@outlook.com>
 *      ChangeLog:  1, Release initial version on "2015年08月11日 14时59分27秒"
 *                 
 ********************************************************************************/
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>

#include "gps.h"
#define GPS_LEN 512

int main (int argc, char **argv)
{
        int     fd=0;
        int     rread=0,i=0;
        char    buffer[GPS_LEN];
        char    *console_name="/dev/ttyS1";
        struct  gps ggps;
        struct  Gtime GGtime;

        printf("will open comport\n");
        fd = open_port(console_name);
        printf("Open Comport is OK!\n");

        if (( i=set_opt( fd,4800,8,'N',1)) < 0)
        {
            perror("set_opt error");
            return -1;
        }

        printf("Begin to Receive GPS data...\n");
        while(1)
        {
            sleep(1);
            rread = read( fd, buffer, sizeof(buffer));
            if( rread > 0)
            {
                analyse(buffer,&ggps,&GGtime);
                print(&ggps,&GGtime);
            }
            sleep(1);
        }
        close(fd);
        return 0;
}


